<?php 
namespace app\common\model;
class Convert extends Common{
	protected $insert = ['addtime'=>SYS_TIME,'acce'];
	protected function getAddtimeAttr($value){
		return date("Y-m-d H:i:s",$value);
	}
	protected function getThumbAttr($value, $data){
		if(strpos($value,"http://") !== false){
			return $value;
		}
		else{
			return $value ? APP_URL.'/'.$value : '';
		}
	}
	protected function getThumbnailAttr($value, $data){
		$thumb = thumb($data['thumb'], 300, 300, 0);
		if(strpos($thumb,"http://") !== false){
			return $thumb;
		}else{
			return $thumb ? APP_URL.'/'.$thumb : '';
		}
	}
	protected function getAccesAttr($value, $data){
		$info = model("Accessory")->get_fileurl($data['acce']);
		if (empty($info)) {
			$info[]= $data['thumb'];
		}
		return $info;
	}
	protected function getAlldataAttr($value, $data){
		$data['addtime'] = date("Y-m-d H:i:s",$data['addtime']);
		return $data;
	}
	protected function setAcceAttr($value, $data){
		if (isset($data['id'])) {
			$acce = $this->where('id', $data['id'])->value('acce');
			if ($acce) {
				model('Accessory')->where('id', 'in', $acce)->delete();
			}
		}
		if (empty($value)) {
			return '';
		}
		$info = [];
		foreach ($value as $v) {
			$image = [
				'fileurl' => $v,
				'typeid' => 9
			];
			$info[] = model('Accessory')->save_data($image);
		}
		return implode(',', $info);
	}
}